package com.icss.mqsp.quartz.servlet;

import com.icss.mqsp.quartz.service.TaskService;
import com.icss.mqsp.quartz.service.impl.TaskServiceImpl;
import com.icss.mqsp.quartz.util.CacheUtil;
import com.icss.pangu.logging.Log;
import com.icss.pangu.logging.LogFactory;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TaskInitServlet
  extends HttpServlet
{
  Log log = LogFactory.getLog(TaskInitServlet.class);
  private static TaskService s = null;
  
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException
  {
    doPost(req, resp);
  }
  
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException
  {}
  
  public void init()
    throws ServletException
  {
    this.log.info("定时任务启动...开始");
    CacheUtil.getUpdateTime();
    
    CacheUtil.setRatDir(getServletContext().getRealPath(CacheUtil.getRatDir()));
    
    CacheUtil.setRatAutoDir(getServletContext().getRealPath(CacheUtil.getRatAutoDir()));
    this.log.info("rat目录：" + CacheUtil.getRatDir() + ",rat_auto目录：" + CacheUtil.getRatAutoDir());
    s = new TaskServiceImpl();
    s.task();
    this.log.info("定时任务启动...成功");
  }
  
  public void destroy()
  {
    this.log.info("定时任务毁坏...开始");
    s.shutdown();
    this.log.info("定时任务毁坏...成功");
  }
}
